package net.dgg.rz.production.demo.controller;

import net.dgg.framework.tac.utils.bean.DggRestResponse;
import net.dgg.framework.tac.utils.web.commmon.DggBaseController;
import net.dgg.iboss.base.util.CustomerNumberEncryptionUtil;
import net.dgg.iboss.base.util.DesUtil;
import net.dgg.rz.common.constant.ScProductConstant;
import net.dgg.rz.common.utils.*;
import net.dgg.rz.production.demo.service.DemoService;
import net.dgg.rz.production.entity.dto.ProductOrderDto;
import net.dgg.rz.production.service.ProductOrderService;
import net.dgg.tmd.foundation.platform.common.util.TranslateUtil;
import net.dgg.tmd.foundation.platform.datapermission.entity.DataAuthDTO;
import net.dgg.tmd.foundation.platform.datapermission.service.DataPermissionAssocService;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;

/**
 * Created by zyou on 2018/12/14.
 */
@Controller
@RequestMapping("/demo")
public class DemoController extends DggBaseController {
    @Autowired
    private DemoService demoService;
    @Autowired
    private ProductOrderService productOrderService;
    @Autowired
    private TranslateUtil translateUtil;
    @Autowired
    private DesUtil desUtil;
    @Autowired
    private DataPermissionAssocService dataPermissionAssocService;

    @RequestMapping("/demo")
    public String demo(Model model){
        model.addAttribute("TIME_OUT", ScProductConstant.TIME_OUT);
        return "rzsc/demo/demo";
    }

    @RequestMapping("/list")
    @ResponseBody
    public DggRestResponse list(@RequestParam Map params){
        params.put("orderDir", "desc");
        params.put("orderColumn", "t.update_time");
        List<ProductOrderDto> list = productOrderService.scOrderWithPage(params);
        String[] transColum = {"originCode", "status"};
        list = translateUtil.translateList(transColum, list);
        String[] hideColum = {"customerPhone"};//隐藏
        list = desUtil.decryptList(hideColum, list);
        list = CustomerNumberEncryptionUtil.encryptionList(hideColum, list);
        return new DataTableResponse().data(params, list);
    }


    /**
     * 导出明细账
     */
    @RequestMapping(value = "excel_export")
    @ResponseBody
    public void exportDetailExcelAll(@RequestParam Map params) {
        int[] widths = new int[] { 512*8, 512*8, 512*8};
        int[] styleArr = new int[] { -1, 0, 1};
        List<ProductOrderDto> list = productOrderService.scOrderWithPage(params);
        String[] title = new String[]{"ID","编号","客户姓名"};
        String[] keyArray = new String[] {"id", "orderNo","customerName"};
        ExcelTool.execlExport(list,"demo",title,keyArray,widths,styleArr);
    }

}
